<template >
  <div class='regist'>
    <div class="content">
      <div class='left'>
        <div class="logo-content">
          <img src="../../assets/login_logo.png" alt="">
        </div>
        <h1> 易联求职校园招聘系统 </h1>
        <h1>为了更好的未来</h1>
      </div>
      <div class="right">
        <div class="form">
          <h2>欢迎登录</h2>
          <el-form
            ref="loginForm"
            label-width="80px"
            label-position="left"
            :model="form"
            :rules="rules1"
          >
            <el-form-item label="用户名" prop="username">
              <el-input
                size="mini"
                v-model="form.username"
                auto-complete="off"
                placeholder="请输入用户名"
              ></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password" class="pass">
              <el-input
                id="password"
                size="mini"
                type="password"
                v-model="form.password"
                auto-complete="off"
                placeholder="请输入密码"
              ></el-input>
            </el-form-item>
            <el-form-item>
                <div
                  style="
                    display: flex;
                    justify-content: space-between;
                    width: 100%;
                  "
                >
                  <el-button
                    id="enterBtn"
                    type="primary"
                    style="width: 100%"
                    @click="submit('loginForm')"
                    >登录</el-button
                  >
                </div>
              </el-form-item>
          </el-form>
          <p>没有账号？ 点击 <router-link style="color: #9aa5df;" to="/regist">去注册</router-link></p>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import './styles.scss'
import {
  login
} from '../../service'
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      rules1: {
        username: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
        ],
        password: [{ required: true, message: "密码不能为空", trigger: "blur" },],
      },
    };
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let params = {
            username: this.form.username,
            password: this.form.password,
          };
          login(params).then((data) => {
            if (data.code === 200) {
              localStorage.setItem(
                "meiyaWebInfo",
                JSON.stringify({
                  ...data.user,
                  token: "Bearer " + data.token,
                })
              );
              this.$message.success("登录成功！");
              // 根据用户类型 跳转
              if (data.user.type === '2') {
                this.$router.push({
                  path: "/publish",
                });
                return
              }
              this.$router.push({
                path: "/",
              });
              // location.reload()
            } else {
              this.$message.error(data.msg[0].msg);
            }
          });
        }
      });
    },
  },
};

</script>

<style>
::v-deep .el-upload__input {
  display: none!important;
}
</style>


